home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / ipdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  2.3 KB  |  111 lines

  1. /* IP header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4.  /* Mods by PA0GRI */
  5. #include <stdio.h>
  6. #include "global.h"
  7. #include "config.h"
  8. #include "mbuf.h"
  9. #include "internet.h"
  10. #include "iface.h"
  11. #include "ip.h"
  12. #include "trace.h"
  13. #include "netuser.h"
  14.  
  15. #ifdef TNOS_68K
  16. #define fprintf traceprintf
  17. #endif
  18.  
  19. void
  20. ip_dump(fp,bpp,check)
  21. FILE *fp;
  22. struct mbuf **bpp;
  23. int check;
  24. {
  25.     struct ip ip;
  26.     int16 ip_len;
  27.     int16 length;
  28.     int16 csum;
  29.  
  30.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  31.         return;    
  32.  
  33.     fprintf(fp,"IP:");
  34.     /* Sneak peek at IP header and find length */
  35.     ip_len = ((*bpp)->data[0] & 0xf) << 2;
  36.     if(ip_len < IPLEN){
  37.         fprintf(fp," bad header\n");
  38.         return;
  39.     }
  40.     if(check)
  41.         csum = cksum(NULLHEADER,*bpp,ip_len);
  42.     else
  43.         csum = 0;
  44.  
  45.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  46.  
  47.     /* Trim data segment if necessary. */
  48.     length = ip.length - ip_len;    /* Length of data portion */
  49.     trim_mbuf(bpp,length);    
  50.     fprintf(fp," len %u",ip.length);
  51.     fprintf(fp," %s",inet_ntoa(ip.source));
  52.     fprintf(fp,"->%s ihl %u ttl %u",
  53.         inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  54.     if(ip.tos != 0)
  55.         fprintf(fp," tos %u",uchar(ip.tos));
  56.     if(ip.offset != 0 || ip.flags.mf)
  57.         fprintf(fp," id %u offs %u",ip.id,ip.offset);
  58.     if(ip.flags.congest)
  59.         fprintf(fp," CE");
  60.     if(ip.flags.df)
  61.         fprintf(fp," DF");
  62.     if(ip.flags.mf){
  63.         fprintf(fp," MF");
  64.         check = 0;    /* Bypass host-level checksum verify */
  65.     }
  66.     if(csum != 0)
  67.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  68.  
  69.     if(ip.offset != 0){
  70. #ifdef TNOS_68K
  71.         fprintf (fp, "\n");
  72. #else
  73.         putc('\n',fp);
  74. #endif
  75.         return;
  76.     }
  77.     switch(uchar(ip.protocol)){
  78.     case TCP_PTCL:
  79.         fprintf(fp," prot TCP\n");
  80.         tcp_dump(fp,bpp,ip.source,ip.dest,check);
  81.         break;
  82.     case UDP_PTCL:
  83.         fprintf(fp," prot UDP\n");
  84.         udp_dump(fp,bpp,ip.source,ip.dest,check);
  85.         break;
  86.     case ICMP_PTCL:
  87.         fprintf(fp," prot ICMP\n");
  88.         icmp_dump(fp,bpp,ip.source,ip.dest,check);
  89.         break;
  90.     case IP_PTCL:
  91.         fprintf(fp," prot IP\n");
  92.         ip_dump(fp,bpp,check);
  93.         break;
  94. #ifdef AX25
  95.     case AX25_PTCL:
  96.         fprintf(fp," prot AX25\n");
  97.         ax25_dump(fp,bpp,check);
  98.         break;
  99. #endif
  100. #ifdef  RSPF
  101.     case RSPF_PTCL:
  102.         fprintf(fp," prot RSPF\n");
  103.         rspf_dump(fp,bpp,ip.source,ip.dest,check);
  104.         break;
  105. #endif
  106.     default:
  107.         fprintf(fp," prot %u\n",uchar(ip.protocol));
  108.         break;
  109.     }
  110. }
  111.